package com.bidevalution.controller.task;

import com.bidevalution.business.service.BeBudgetItemService;
import com.qtp.core.util.OConvertUtils;
import lombok.extern.log4j.Log4j2;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * 清单抽取定时任务
 * Created by glodon on 2019-11-18.
 */
@Log4j2
@Component
public class ExtractBugetNodeTask {
    @Autowired
    private BeBudgetItemService beBudgetItemService;
    private Logger log = LogManager.getLogger(getClass());
    /**
     * 抽取清单
     * @throws Exception
     */
    @Scheduled(cron = "0 */3 *  * * * ")
    public void extract() throws Exception {
        //查询今日开标的项目
        List<Map<String, Object>> projectMap = beBudgetItemService.queryNeedExtractInfo();
       if(projectMap != null && projectMap.size() > 0) {
            for(Map<String, Object> map : projectMap) {
                try {
                    //抽取清单
                    beBudgetItemService.extractBudgetItem(OConvertUtils.getString(map.get("tdProjectId")));
                } catch (Exception e) {
                    log.error("项目id=["+OConvertUtils.getString(map.get("tdProjectId"))+"]清单抽取失败，", e);
                }
            }
        }
    }

    /**
     * 清单数据推送
     * @throws Exception
     */
    @Scheduled(cron = "0 */3 *  * * * ")
    public void pushBudgetInfo() throws Exception {
        //清单数据推送
        beBudgetItemService.pushBudgetInfo();
    }
}
